﻿<mui:ModernWindow x:Class="LocultMetro.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:behav="clr-namespace:LocultApp.Behaviours;assembly=LocultApp"
        xmlns:conv="clr-namespace:LocultApp.Converter;assembly=LocultApp"
        xmlns:proc="clr-namespace:LocultApp.ViewModels.StringSource;assembly=LocultApp"

        xmlns:pagevm="clr-namespace:LocultApp.ViewModels.Pages;assembly=LocultApp"
        xmlns:pageview="clr-namespace:LocultApp.Views.Pages;assembly=LocultApp"
        xmlns:pageviews="clr-namespace:LocultApp.Controls.Exception;assembly=LocultApp"
        xmlns:local="clr-namespace:LocultApp.Local;assembly=LocultApp"
        
        behav:DialogCloser.DialogResult="{Binding AppLifeCycle.DialogCloseResult}"        

        Title="{Binding AppLifeCycle.Application_Title}" Height="750" Width="925"

        xmlns:mui="http://firstfloorsoftware.com/ModernUI"
        Style="{DynamicResource LocultBlankWindow}"
    >
    <Grid>
        <Grid.Resources>
            <conv:InverseBooleanConverter x:Key="ConvertInverseBool" />
            <conv:BoolToVisibilityConverter x:Key="ConvertBoolToVisibility" />
            <behav:BindingProxy x:Key="DataContextProxy" Data="{Binding}" />
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Grid Margin="3">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <!-- Button Section on the very left top side of main windoow -->
            <StackPanel Orientation="Horizontal" Grid.Column="0">
                <Button Content="{x:Static local:Strings.STR_CAPTION_EXIT}" Command="{Binding AppLifeCycle.ExitApp}" Margin="0,0,3,0" />
                <Button Content="{x:Static local:Strings.STR_CAPTION_SAVE_SOLUTION}" Command="{Binding PageManager.SaveSolutionCommand}" Margin="0,0,3,0" />
                <Button Content="{x:Static local:Strings.STR_CAPTION_SHOW_STARTPAGE}" Command="{Binding PageManager.ShowStartPageCommand}" Margin="0,0,3,0" />
            </StackPanel>

            <!-- Button Section on the very right top corner of main windoow -->
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Column="1">
                <!-- Cancel changing settings is shown only when settings view is active -->
                <Button Content="{x:Static local:Strings.STR_CAPTION_CANCEL}" Command="{Binding PageManager.CancelSettingsCommand}"
                        Margin="0,0,3,0" Visibility="{Binding PageManager.IsSettingsPageVisible, Mode=OneWay,UpdateSourceTrigger=PropertyChanged, Converter={StaticResource ConvertBoolToVisibility}}">
                </Button>
                <ToggleButton DataContext="{Binding PageManager}"
                    Content="{x:Static local:Strings.STR_CAPTION_SETTINGS}"
                    Command="{Binding ShowSettingsCommand}"
                    IsChecked="{Binding IsSettingsPageVisible, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                    Margin="0,0,3,0" />
                <!-- IsCheck is ?bool -->
            </StackPanel>
        </Grid>

        <Grid Grid.Row="1">
            <Grid.Resources>
                <!--
                These datatemplates map a type of viewmodel into their view.
                This map definition is used below in the ContentPresenter to
                show the correct page for each type of view.
                -->
                <DataTemplate DataType="{x:Type pagevm:StartPageViewModel}">
                    <ScrollViewer Grid.Row="2" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                        <pageview:StartPageView
                              IsEnabled="{Binding Data.IsProcessingSolution, Source={StaticResource DataContextProxy}, Converter={StaticResource ConvertInverseBool}}"
                        />
                    </ScrollViewer>
                </DataTemplate>
                <DataTemplate DataType="{x:Type pagevm:EditPageViewModel}">
                    <!-- Has its own scroll viewer in Grid Control -->
                    <pageview:EditPage
                        IsEnablePage="{Binding Data.IsProcessingSolution, Source={StaticResource DataContextProxy}, Converter={StaticResource ConvertInverseBool}}"
                        />
                </DataTemplate>
                <DataTemplate DataType="{x:Type pagevm:SettingsPageViewModel}">
                    <ScrollViewer Grid.Row="2" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                        <pageview:SettingsPage
                        IsEnablePage="{Binding Data.IsProcessingSolution, Source={StaticResource DataContextProxy}, Converter={StaticResource ConvertInverseBool}}"
                        />
                    </ScrollViewer>
                </DataTemplate>
            </Grid.Resources>

            <Grid.RowDefinitions>
                <!-- Progress row should not be visible unless a task is currently in progress -->
                <RowDefinition Height="Auto" />
                <!-- ExceptionView should not be visible unless the last operation ended with an error -->
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <Grid Grid.Row="0">
                <Grid.Resources>
                    <conv:BoolToVisibilityConverter x:Key="BoolToHiddenConverter" TrueValue="Visible" FalseValue="Hidden" />
                </Grid.Resources>

                <!-- Display a progress bar and Cancel button when Machine based translation is executed -->
                <Grid Grid.Row="0" Visibility="{Binding Path=PageManager.IsProcessing, Converter={StaticResource BoolToHiddenConverter}}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <ProgressBar Grid.Column="0" IsIndeterminate="True" Height="10" Margin="3" />
                    <Button Grid.Column="1"
                            Content="{x:Static local:Strings.STR_CAPTION_CANCEL}"
                            Command="{Binding StringDiff.CancelTranslationCommand, FallbackValue={x:Null}}" Margin="3"/>
                </Grid>
            </Grid>

            <Grid Grid.Row="1">
                <Grid.Resources>
                    <conv:BoolToVisibilityConverter x:Key="BoolToVisible" TrueValue="Visible" FalseValue="Collapsed" />
                </Grid.Resources>

                <pageviews:ExceptionView Grid.Row="1"
                                        DataContext="{Binding PageManager.ViewException}"
                                        Visibility="{Binding IsExceptionVisible, Converter={StaticResource BoolToVisible}}"
                                        Margin="3,15,3,3" />
            </Grid>

            <ContentPresenter Grid.Row="3" Content="{Binding PageManager.CurrentPage}" />
        </Grid>
    </Grid>
</mui:ModernWindow>
